trigger inactivateUserForCancelledAccount on Account (before insert, before update) 
{    
    List<id> accountidListforCancel = new List<id>();    
    List<id> accountidListforActivation = new List<id>();        
    if(trigger.IsInsert)
    {                        
        for (Account a:trigger.new){  
        
        system.Debug('## Status__c'+a.Status__c);
        
            if(a.Status__c == 'Active'){                        
                accountidListforActivation.add(a.id);                    
                }                
        }   
        
        system.Debug('## accountidListforActivation.size() '+accountidListforActivation.size());    
         
        if(accountidListforActivation.size() != 0){            
            deactivateUser.activatePortalUser(accountidListforActivation);        
        }    
    }        
    if(trigger.IsUpdate)
    {            
        for (Account acc:trigger.new)
        {    
            system.Debug('## Status__c'+acc.Status__c);
                
            if(acc.Status__c != trigger.oldMap.get(acc.id).Status__c){   
            
            system.Debug('## Status__c'+acc.Status__c);
                         
                if(acc.Status__c == 'Cancelled'){                    
                    accountidListforCancel.add(acc.id);                
                }                
                if(acc.Status__c == 'Active'){                    
                    accountidListforActivation.add(acc.id);                
                }            
            }        
        }      
        
        system.Debug('## accountidListforActivation.size() '+accountidListforActivation.size());
          
        if(accountidListforCancel.size() != 0){            
            deactivateUser.deactivatePortalUser(accountidListforCancel);        
        }        
        if(accountidListforActivation.size() != 0){            
            deactivateUser.activatePortalUser(accountidListforActivation);        
            }    
        }
}